package org.jeecg.modules.controller.market;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.entity.DbInvoiced;
import org.jeecg.modules.entity.DbInvoicesInfo;
import org.jeecg.modules.service.IDbInvoicesInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: db_invoices_info
 * @Author: jeecg-boot
 * @Date: 2024-07-02
 * @Version: V1.0
 */
@Api(tags = "客户开票信息管理")
@RestController
@RequestMapping("/dbInvoicesInfo")
@Slf4j
public class DbInvoicesInfoController extends JeecgController<DbInvoicesInfo, IDbInvoicesInfoService> {
    @Autowired
    private IDbInvoicesInfoService dbInvoicesInfoService;
    /**
     * 通过客户id查找开票信息
     * @param cusId
     * @return
     */
    @ApiOperation(value="db_invoices_info-通过客户id查找客户开票信息", notes="db_invoices_info-通过客户id查找客户开票信息")
    @GetMapping(value = "/listByCusId")
    public Result<List<DbInvoicesInfo>> queryPageList(@RequestParam(name="cusId",required=true) String  cusId) {
        QueryWrapper<DbInvoicesInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("cus_id",cusId);
        List<DbInvoicesInfo> list = dbInvoicesInfoService.list(queryWrapper);
        return Result.OK(list);
    }
    /**
     * 分页列表查询
     *
     * @param dbInvoicesInfo
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "db_invoices_info-分页列表查询")
    @ApiOperation(value = "分页列表查询客户开票信息", notes = "分页列表查询客户开票信息")
    @GetMapping(value = "/list")
    public Result<IPage<DbInvoicesInfo>> queryPageList(DbInvoicesInfo dbInvoicesInfo,
                                                       @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                       @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                       HttpServletRequest req) {
        QueryWrapper<DbInvoicesInfo> queryWrapper = QueryGenerator.initQueryWrapper(dbInvoicesInfo, req.getParameterMap());
        Page<DbInvoicesInfo> page = new Page<DbInvoicesInfo>(pageNo, pageSize);
        IPage<DbInvoicesInfo> pageList = dbInvoicesInfoService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    @ApiOperation(value = "查询客户开票信息", notes = "查询客户开票信息")
    @GetMapping(value = "/listDbInvoicesInfo")
    public Result<List<DbInvoicesInfo>> listDbInvoicesInfo(DbInvoicesInfo dbInvoicesInfo,
                                                           HttpServletRequest req) {
        QueryWrapper<DbInvoicesInfo> queryWrapper = QueryGenerator.initQueryWrapper(dbInvoicesInfo, req.getParameterMap());
        List<DbInvoicesInfo> diList = dbInvoicesInfoService.list();
        return Result.OK(diList);
    }


    @ApiOperation(value = "根据id查询客户开票信息", notes = "根据id查询客户开票信息")
    @GetMapping(value = "/getDbInvoicesInfoById")
    public Result<DbInvoicesInfo> getDbInvoicesInfoById(String invoicesInfoId,
                                                           HttpServletRequest req) {

        DbInvoicesInfo dbInvoicesInfo = dbInvoicesInfoService.getById(invoicesInfoId);
        return Result.OK(dbInvoicesInfo);
    }

    /**
     * 添加
     *
     * @param dbInvoicesInfo
     * @return
     */
    @AutoLog(value = "db_invoices_info-添加")
    @ApiOperation(value = "添加客户开票信息", notes = "添加客户开票信息")
    //@RequiresPermissions("org.jeecg.modules:db_invoices_info:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody DbInvoicesInfo dbInvoicesInfo) {
        dbInvoicesInfoService.save(dbInvoicesInfo);
        return Result.OK("添加成功！");
    }

    /**
     * 编辑
     *
     * @param dbInvoicesInfo
     * @return
     */
    @AutoLog(value = "db_invoices_info-编辑")
    @ApiOperation(value = "编辑客户开票信息", notes = "编辑客户开票信息")
    //@RequiresPermissions("org.jeecg.modules:db_invoices_info:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody DbInvoicesInfo dbInvoicesInfo) {
        dbInvoicesInfoService.updateById(dbInvoicesInfo);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "db_invoices_info-通过id删除")
    @ApiOperation(value = "通过id删除客户开票信息", notes = "通过id删除客户开票信息")
    //@RequiresPermissions("org.jeecg.modules:db_invoices_info:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        dbInvoicesInfoService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "db_invoices_info-批量删除")
    @ApiOperation(value = "批量删除客户开票信息", notes = "批量删除客户开票信息")
    //@RequiresPermissions("org.jeecg.modules:db_invoices_info:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.dbInvoicesInfoService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "db_invoices_info-通过id查询")
    @ApiOperation(value = "通过id查询客户开票信息", notes = "通过id查询客户开票信息")
    @GetMapping(value = "/queryById")
    public Result<DbInvoicesInfo> queryById(@RequestParam(name = "id", required = true) String id) {
        DbInvoicesInfo dbInvoicesInfo = dbInvoicesInfoService.getById(id);
        if (dbInvoicesInfo == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(dbInvoicesInfo);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param dbInvoicesInfo
     */
    //@RequiresPermissions("org.jeecg.modules:db_invoices_info:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, DbInvoicesInfo dbInvoicesInfo) {
        return super.exportXls(request, dbInvoicesInfo, DbInvoicesInfo.class, "db_invoices_info");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    //@RequiresPermissions("db_invoices_info:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, DbInvoicesInfo.class);
    }

}
